<?php

namespace catchAdmin\customs\model\search;

trait OrderSearch
{
    /*
     *  订单编号
     */
    public function searchorderIdAttr($query, $value, $data)
    {
        return $query->whereLike('orderId', $value);
    }

    /*
     * 订购人证件号
     */
    public function searchConsigneeCodeAttr($query, $value, $data)
    {
        return $query->whereLike('ConsigneeCode', $value);
    }

    /*
     * 收货联系人
     */
    public function searchcontactNameAttr($query, $value, $data)
    {
        return $query->whereLike('contactName', $value);
    }

    /*
    * 海关订单推送
    */
    public function searchpushOrderAttr($query, $value, $data)
    {
        return $query->where('push_order', $value);
    }

    /**
     * 运单接口状态
     */
    public function searchpushInventoryAttr($query, $value, $data)
    {
        return $query->where('push_inventory', $value);
    }

    /**
     * 订单日期
     */
    public function searchorderDateAttr($query, $value, $data)
    {
        if (!empty($value)) {
            return $query->whereTime('orderDate', 'between', [$value[0], $value[1]]);
        }
    }

    /**
     * 放行日期
     */
    public function searchcompleteDateTimeAttr($query, $value, $data)
    {
        if (!empty($value)) {
            return $query->where('completeDateTime',  'between', [$value[0].'000000', $value[1].'000000']);
        }
    }

    /**
     * 订购人姓名
     */
    public function searchbuyerNameAttr($query, $value, $data)
    {
        return $query->whereLike('buyerName', $value);
    }

    /**
     * 订购人姓名
     */
    public function searchinvtNoAttr($query, $value, $data)
    {
        return $query->whereLike('invt_no', $value);
    }

    /**
     * 运单接口状态
     */
    public function searchwaybillStatusAttr($query, $value)
    {
        return $query->whereLike('waybill_status', $value);
    }

    /**
     * 商户名
     */
    public function searchmerchantNameAttr($query, $value, $data)
    {
        return $query->whereLike('b.merchant_name', $value);
    }

    /**
     * ids
     */
    public function searchidsAttr($query, $value, $data)
    {
        return $query->where('orderId', 'in', $value);
    }

     public function searchPushStatusAttr($query, $value, $data)
     {
       return $query->where('push_status', $value);
     }


    // public function searchStatusAttr($query, $value, $data)
    // {
    //   return $query->where('status', $value);
    // }

    //查询订单类型
    public function searchOrderTypeAttr($query, $value, $data){
        if($value == 'bonded'){
            return $query->where('_order_type', 11);
        }else{
            return $query->where('_order_type', '<>', 11);
        }
    }

}